package com.hanrui.android.fragment.message.audit.askforleave;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.AskForLeaveDetailBean;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.net.contract.message.audit.askforleave.AskForLeaveDetailContract;
import com.hanrui.android.net.presenter.message.audit.askforleave.AskForLeaveDetailPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 请假审批基本信息
 *
 */

public class AskForLeaveDetailFragment extends BaseFragment<AskForLeaveDetailPresenter> implements AskForLeaveDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.head_company)
    TextView headCompany;
    @BindView(R.id.duty_company)
    TextView dutyCompany;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.money_meet)
    TextView moneyMeet;
    @BindView(R.id.reson_ll)
    LinearLayout resonLl;
    @BindView(R.id.reson)
    TextView reson;
    @BindView(R.id.year_holidayll)
    LinearLayout yearHolidayll;
    @BindView(R.id.assign_body)
    TextView assignBody;
    @BindView(R.id.wind_meet)
    TextView windMeet;
    @BindView(R.id.holiday_num)
    TextView holidayNum;
    @BindView(R.id.holiday)
    TextView holiday;
    @BindView(R.id.holiday_next)
    TextView holidayNext;
    @BindView(R.id.duty_people)
    TextView duty_people;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;

    String taskId,procInsId,bizId;

    List<FilesBean> filesBeanList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_askforleavedetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.askForLeaveBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static AskForLeaveDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        AskForLeaveDetailFragment fragment = new AskForLeaveDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @OnClick({R.id.enclosure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.enclosure:
                MyDownLoadActivity.start(getActivity(),filesBeanList);
                break;
        }
    }

    @Override
    public void askForLeaveBizDetail(AskForLeaveDetailBean data) {

        if (null != data) {

            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                filesBeanList.clear();
                filesBeanList.addAll(data.getFiles());
                enclosureNum.setText("["+data.getFiles().size()+"]");

            		}

            mainTitle.setText(data.getDetail().getApplicantName()+"的请假审批");
            subheadTitle.setText(data.getDetail().getApplyTime());
            name.setText(data.getDetail().getTitle());
            thingTitle.setText(data.getDetail().getApplyTime());
            time.setText(data.getDetail().getApplicantName());
            leaders.setText(data.getDetail().getOfficeName());
            headCompany.setText(data.getDetail().getLeaveType());
            dutyCompany.setText(data.getDetail().getLeaveDays());
            voteMeet.setText(data.getDetail().getStartTime());
            moneyMeet.setText(data.getDetail().getEndTime());
            if (data.getDetail().getLeaveType().equals("年假")) {

                resonLl.setVisibility(View.GONE);
                yearHolidayll.setVisibility(View.VISIBLE);
                assignBody.setText(data.getDetail().getWorkDate());
                windMeet.setText(data.getDetail().getWorkAge());
                holidayNum.setText(data.getDetail().getRestDays());
                holiday.setText(data.getDetail().getHaveRestDays());
                holidayNext.setText(data.getDetail().getLastDays());
                duty_people.setText(data.getDetail().getPlan());
                from.setText(data.getDetail().getRemarks());

            		}else {

                resonLl.setVisibility(View.VISIBLE);
                yearHolidayll.setVisibility(View.GONE);
                reson.setText(data.getDetail().getReason());

            }



        }

    }

}
